home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15019 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: cypher.3do.com!user
  2. From: tsw@3do.com (Tom Watson)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: HELP...HELP
  5. Date: Tue, 16 Apr 1996 12:03:47 -0800
  6. Organization: The 3DO Corporation
  7. Distribution: world
  8. Message-ID: <tsw-1604961203470001@cypher.3do.com>
  9. References: <316EF6A1.41C6@ift.ulaval.ca>
  10. NNTP-Posting-Host: cypher.3do.com
  11.  
  12. In article <316EF6A1.41C6@ift.ulaval.ca>, Ferid Baklouti
  13. <baklouti@ift.ulaval.ca> wrote:
  14.  
  15. > Hello everyone,
  16. > imagine this command under a unix system :
  17. >         program1 < file | program2 | program3 > file.results
  18. > i want the "program2" to be able to detect the name of "file" given on
  19. > the standard input <stdin> to the program1.
  20. > in the file stdio.h, I only find the things below which doesn't contain
  21. > the name of the file.
  22. <<<copy of his <stdio.h> deleted>>>
  23.  
  24. The association of the file with a standard I/O stream is outside the
  25. scope of the <stdio.h> functions (and standard C for that matter).  Once
  26. the file has been opened for input (in your example 'program1') the
  27. association of a name with the stream (FILE structure) is lost.  In your
  28. pipeline example above, even 'program1' doesn't know what the name of its
  29. input is since the invoking program (the shell in Unix) is the one that
  30. associated the file name 'file' with the input stream.
  31.  
  32. All you know is that the data is coming from "somewhere" and where is none
  33. of your concern, nor need it be any of your concern.  About the only thing
  34. you can tell (with calls to Unix functions) is that you are dealing with a
  35. device, or a file.  The information is not available if you are using the
  36. <stdio.h> library.
  37.  
  38. Now, if you desire to invoke your set of programs with the name 'file' and
  39. have the final output as 'file.results' (as in the example above), I would
  40. suggest a small shell script that takes an argument.  To do that is a
  41. topic for shell scripting and not part of the 'comp.lang.c' newsgroup.
  42.  
  43. Short answer:  "You can't do that!".
  44.  
  45. -- 
  46. Tom Watson
  47. tsw@3do.com         (Home: tsw@johana.com)
  48.